package com.example.spring_mvc.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-04-12
 * Time: 19:31
 */

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //通过判断Session 是否登录
        HttpSession session = request.getSession(false);
        if (session == null && request.getAttribute("USER") == null){
            System.out.println("没有登录");
            return false;
        }

        return true;

    }
}
